package com.link2room.quintesson.controller.manager;

import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.jpa.result.QueryResult;
import com.link2room.quintesson.dto.param.manager.TaobaoXhotelManagerParamDto;
import com.link2room.quintesson.dto.result.manager.TaobaoXhotelDto;
import com.link2room.quintesson.facade.ITaobaoXhotelFacadeService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by VegetaKo on 2017/1/12.
 */
@RestController
@RequestMapping("/manager/TaobaoXhotels")
public class TaobaoXhotelManagerController {

    @Resource
    private ITaobaoXhotelFacadeService taobaoXhotelFacadeService;

    @RequestMapping(method = RequestMethod.GET)
    public BaseResultDto taobaoXhotelList(
            @RequestParam(value = "lhotelCode" ,required = false) String lhotelCode,
            @RequestParam(value = "city" ,required = false) Long city,
            @RequestParam(value = "brands" ,required = false) String brands,
            @RequestParam(value = "currentPage" ,required = false) Integer currentPage,
            @RequestParam(value = "pageSize" ,required = false) Integer pageSize
    ) throws Exception {
        TaobaoXhotelManagerParamDto taobaoXhotelManagerParamDto=new TaobaoXhotelManagerParamDto();
        taobaoXhotelManagerParamDto.setLhotelCode(lhotelCode);
        taobaoXhotelManagerParamDto.setCity(city);
        taobaoXhotelManagerParamDto.setBrands(brands);
        taobaoXhotelManagerParamDto.setCurrentPage(currentPage);
        taobaoXhotelManagerParamDto.setPageSize(pageSize);
        QueryResult<TaobaoXhotelDto> taobaoXhotelResult = taobaoXhotelFacadeService.listTaobaoXhotel(taobaoXhotelManagerParamDto);
        BaseResultDto<TaobaoXhotelDto> baseResultDto=new BaseResultDto<>();
        baseResultDto.setResultCode(0);
        baseResultDto.setQueryResult(taobaoXhotelResult);
        return baseResultDto;
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public BaseResultDto taobaoXhotel(
            @PathVariable Long id
    ) throws Exception {
        TaobaoXhotelManagerParamDto taobaoXhotelManagerParamDto=new TaobaoXhotelManagerParamDto();
        taobaoXhotelManagerParamDto.setId(id);
        TaobaoXhotelDto taobaoXhotelDto = taobaoXhotelFacadeService.findTaobaoXhotel(taobaoXhotelManagerParamDto);
        BaseResultDto<TaobaoXhotelDto> baseResultDto=new BaseResultDto<>();
        baseResultDto.setResultCode(0);
        baseResultDto.setResultInfo(taobaoXhotelDto);
        return baseResultDto;
    }

    @RequestMapping(method= RequestMethod.PUT)
    public BaseResultDto updateTaobaoXhotelList(
            @RequestBody TaobaoXhotelManagerParamDto taobaoXhotelManagerParamDto
    )throws Exception{
        List<TaobaoXhotelDto> taobaoXhotelDtoList = taobaoXhotelFacadeService.saveOrUpdateTaobaoXhotelList(taobaoXhotelManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setListToQueryResult(taobaoXhotelDtoList);
        return l2rRs;
    }

    @RequestMapping(value = "/TaobaoXhotel",method= RequestMethod.PUT)
    public BaseResultDto updateTaobaoXhotel(
            @RequestBody TaobaoXhotelManagerParamDto taobaoXhotelManagerParamDto
    )throws Exception{
        TaobaoXhotelDto taobaoXhotelDto=taobaoXhotelFacadeService.saveOrUpdateTaobaoXhotel(taobaoXhotelManagerParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(taobaoXhotelDto);
        return l2rRs;
    }
}
